import {GoodController} from "../controller/GoodController";
import {TimeController} from "../controller/TimeController";
import {ControllerNo, TimeControllerOpt} from "../controller/model/ControllerOpt";
import {TriggerFactory} from "../frame/TriggerFactory";
import {UnitModel} from "../frame/apiModel/adapterModel/model3/UnitModel";
import {ItemModel} from "../frame/apiModel/adapterModel/model3/ItemModel";
import {PlayerModel} from "../frame/apiModel/adapterModel/model4/PlayerModel";
import {StoreController} from "../controller/StoreController";
import {UnitDataKey} from "../frame/dataSource/DataSource";

export function initGoodEffectTrigger() {
    const goodCallBack = function (this: void, activeUnit: UnitModel, item: ItemModel, activePlayer: PlayerModel) {
        const callBack = function () {
            const playerCheck = activePlayer?.isNotEndPlaying();
            if (playerCheck) {
            } else {
                return;
            }
            if (activeUnit?.isValid()) {
            } else {
                return;
            }
            GoodController.getInstance().insertAttrByGoodData(activeUnit, item);
            StoreController.getInstance().addStoreTask(activePlayer, ControllerNo.GoodController)
        }
        // 丢弃装备时判断装备还在人物身上  加一个延迟
        const opt: TimeControllerOpt = new TimeControllerOpt(undefined, callBack, 1);
        TimeController.getInstance().startTimer({ opt, time: 0.01 });
    }
    TriggerFactory.getInstance().registerUnitManipulateItem(goodCallBack)
}